package org.example.game.history;

import java.util.HashMap;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/05/19 10:43
 */
public class Solution100308 {

    public static void main(String[] args) {
        Solution100308 solution100308 = new Solution100308();
        int[] nums = new int[]{1,4};
        int[][] queries = new int[][]{{0,1}};

        boolean[] result = solution100308.isArraySpecial(nums, queries);
        for(boolean f : result){
            System.out.println(f);
        }

    }


    public boolean[] isArraySpecial(int[] nums, int[][] queries) {
        HashMap<Integer, Integer> subMap = new HashMap<>();
        if(nums.length == 1){
            subMap.put(0, 1);
        }else {
            int start = 0;
            boolean ou;
            for(int i=1;i<nums.length;i++){
                ou = nums[i-1]%2 == 0;
                if((nums[i]%2 == 0 && ou) || (nums[i]%2 != 0 && !ou)){
                    for(int j=start;j<i;j++){
                        subMap.put(j, Math.max(i-j-1, 0));
                    }
                    start = i;
                }
            }

           if(start < nums.length){
                for(int j=start;j<nums.length;j++){
                    subMap.put(j, Math.max(nums.length-j-1, 0));
                }
            }

        }

        boolean[] result = new boolean[queries.length];
        for(int i=0;i<queries.length;i++){
            if(queries[i][0] == queries[i][1]){
                result[i] = true;
            } else if(subMap.get(queries[i][0]) == null || subMap.get(queries[i][0]) < queries[i][1]-queries[i][0]){
                result[i] = false;
            }else {
                result[i] = true;
            }
        }
        return result;
    }


    public boolean isArraySpecial(int[] nums) {
        if(nums.length == 1){
            return true;
        }
        boolean ou;
        for(int i=1;i<nums.length;i++){
            ou = nums[i-1]%2 == 0;
            if((nums[i]%2 == 0 && ou) || (nums[i]%2 != 0 && !ou)){
                return false;
            }
        }
        return true;
    }

}
